//
//  Paper.swift
//  Exam-iOS
//
//  Created by 李胜锋 on 2018/3/5.
//  Copyright © 2018年 李胜锋. All rights reserved.
//

import Foundation
import Moya
import RxSwift

enum PaperAPI {
    ///试用书卷题目列表
    case trial(paperId: Int)
    ///获取试卷所有试题
    case allItems(paperId: Int)
    ///试卷列表
    case paperList(levelId: Int, classId:Int, pageNum: Int)
    ///试卷收藏列表
    case likesList
    ///收藏
    case likes(paperId: Int, itemId: Int, action: Int)
    ///购买试卷
    case buy(paperId: Int)
    ///交卷
    case submit(pUserSummaryId: Int, itemsAnswers: [[String: Any]])
    ///获取收藏试卷试题
    case likesItemList(paperId: Int)
    ///错题列表
    case errorList
    ///获取试卷错题详情
    case errorListItems(paperId: Int, pUserSummaryId: Int)
    ///自评分
    case selfReportScore(pUserSummaryId: Int, itemsScore: [[String: Any]])
    ///记录列表
    case recordList(pageNum: Int, pageSize: Int)
    ///记录详情
    case recordDetail(pUserSummaryId: Int)
}

extension PaperAPI: LSFTargetType {
   
    
    
    var path: String {
        switch self {
        case .trial:
            return "paper/trial"
        case .paperList:
            return "paper/list"
        case .allItems:
            return "paper/all-items"
        case .likesList:
            return "paper/likes-list"
        case .likes:
            return "paper/likes"
        case .buy:
            return "paper/buy"
        case .submit:
            return "paper/submit-answers"
        case .likesItemList:
            return "paper/likes-item-list"
        case .errorList:
            return "paper/wrong-list"
        case .errorListItems:
            return "paper/wrong-item-list"
        case .selfReportScore:
            return "paper/batch-self-reported-score"
        case .recordList:
            return "paper/used-paper-list"
        case .recordDetail:
            return "paper/used-paper-detail"
        }
    }
    
    
    var method: Moya.Method {
        
        switch self {
        case .likes, .buy, .submit, .selfReportScore:
            return .post
            
        case .trial, .paperList, .allItems, .likesList, .likesItemList, .errorList, .errorListItems, .recordList, .recordDetail:
            return .get
        }
    }
    
    var paramaters: [String : Any]? {
        switch self {
        case .trial(let paperId):
            return ["paperId": paperId]

        case .paperList(let levelId, let classId, let pageNum):
            return ["levelId": levelId,
                    "classId": classId,
                    "pageNum": pageNum,
                    "pageSize": 10]
            
        case .likes(let paperId, let itemId, let action):
            return ["paperId": paperId,
                    "itemId": itemId,
                    "action": action]
            
        case .allItems(let paperId):
            return ["paperId": paperId]
            
        case .buy(let paperId):
            return ["paperId": paperId]
            
        case .submit(let pUserSummaryId, let itemsAnswers):
            return ["pUserSummaryId": pUserSummaryId,
                    "itemsAnswers": itemsAnswers]
            
            
        case .likesItemList(let paperId):
            return ["paperId": paperId]
            
        case .errorListItems(let paperId, let pUserSummaryId):
            return ["paperId": paperId,
                    "pUserSummaryId": pUserSummaryId]
            
            
        case .selfReportScore(let pUserSummaryId, let itemsScore):
            return ["pUserSummaryId": pUserSummaryId,
                    "itemsScore": itemsScore]
            
        case .recordList(let pageNum, let pageSize):
            return ["pageNum": pageNum,
                    "pageSize": pageSize]
            
        case .recordDetail(let pUserSummaryId):
            return ["pUserSummaryId": pUserSummaryId]
 
        case .likesList, .errorList:
            return nil

        }
    }
    
}

let paperProvider = LSFMoyaProvider<PaperAPI>.provider()
//let paperProvider = MoyaProvider<PaperAPI>()



